import Vue from "vue";
import store from "../store/index";
import VueRouter from "vue-router";

// 解决报错
const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;
// push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
	if (onResolve || onReject)
		return originalPush.call(this, location, onResolve, onReject);
	return originalPush.call(this, location).catch((err) => err);
};
// replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
	if (onResolve || onReject)
		return originalReplace.call(this, location, onResolve, onReject);
	return originalReplace.call(this, location).catch((err) => err);
};
Vue.use(VueRouter);


const login = () => import("@/views/account/login.vue");
// 官网页面1
const Index = () => import( /* webpackChunkName: "index" */ "@/views/Index.vue");
// const test = () => import(/* webpackChunkName: "test" */ "@/views/test/testTinymce.vue");
// const test = () =>
// 	import( /* webpackChunkName: "test" */ "@/views/test/testCkeditor.vue");
const home_page = () => import("@/views/home/home-page.vue");
// 商品管理
const product_list = () => import("@/views/product/product-list.vue");
const product_form = () => import("@/views/product/product-form.vue");
const product_cate = () => import("@/views/product/product-cate.vue");
const brand_cate = () => import("@/views/product/brand/brand-cate.vue");
const points_product = () => import("@/views/product/points/points-product.vue");
const miaosha_list = () => import("@/views/product/miaosha/miaosha-list.vue");
const miaosha_detail = () => import("@/views/product/miaosha/miaosha-detail.vue");
const miaosha_form = () => import("@/views/product/miaosha/miaosha-form.vue");
const package_product_list = () => import("@/views/product/package/package-product-list.vue");
const package_product_form = () => import("@/views/product/package/package-product-form.vue");
const gift_list = () => import("@/views/product/gift/gift-list.vue");
const gift_form = () => import("@/views/product/gift/gift-form.vue");
const product_unit = () => import("@/views/product/unit/product-unit.vue");
const product_setting = () => import("@/views/product/setting/product-setting.vue");
// 库存管理
// 仓库列表
// 商品库存
// 库存明细
const warehouse_list = () => import("@/views/product/stock/warehouse-list.vue");
const stock_list = () => import("@/views/product/stock/stock-list.vue");
const stock_record = () => import("@/views/product/stock/stock-record.vue");
// 应用营销
// 应用营销 //1-海外运费 2-海外满减 3-积分签到设置 4-积分价值 5-充值赠送
const coupon_list = () => import("@/views/market/coupon/coupon-list.vue");
const coupon_form = () => import("@/views/market/coupon/coupon-form.vue");
const coupon_code_list = () => import("@/views/market/coupon/coupon-code-list.vue");
const coupon_code_form = () => import("@/views/market/coupon/coupon-code-form.vue");
const china_express = () => import("@/views/market/express/china-express.vue");
const foreign_express = () => import("@/views/market/express/foreign-express.vue");
const foreign_trade_rule = () => import("@/views/market/express/foreign-trade-rule.vue");
const points_sign_rule = () => import("@/views/market/points/points-sign-rule.vue");
const points_value_rule = () => import("@/views/market/points/points-value-rule.vue");
const recharge_list = () => import("@/views/market/recharge/recharge-list.vue");
// const recharge_form = () => import("@/views/market/recharge/recharge-form.vue");
const reg_gift = () => import("@/views/market/gift/reg-gift.vue");

//订单管理
const order_list = () => import("@/views/order/order/order-list.vue");
const order_detail = () => import("@/views/order/order/order-detail.vue");
const points_order_list = () => import("@/views/order/points/points-order-list.vue");
const points_order_detail = () => import("@/views/order/points/points-order-detail.vue");
const ship_list = () => import("@/views/order/ship/ship-list.vue");
const ship_detail = () => import("@/views/order/ship/ship-detail.vue");
const review_list = () => import("@/views/order/review/review-list.vue");
const invoice_list = () => import("@/views/order/invoice/invoice-list.vue");
const refund_list = () => import("@/views/refund/refund-list.vue");
const refund_detail = () => import("@/views/refund/refund-detail.vue");
//门店管理
const store_list = () => import("@/views/store/store-list.vue");
// 统计管理
const statistics_product = () => import("@/views/statistics/statistics-product.vue");
const product_transaction = () => import("@/views/statistics/product-transaction.vue");
// 用户管理
const user_list = () => import("@/views/user/user-list.vue");
const user_detail = () => import("@/views/user/user-detail.vue");
const user_level_rule = () => import("@/views/shop-setting/user-level-rule.vue");
const agent_list = () => import("@/views/user/agent/agent-list.vue");
const feedback_list = () => import("@/views/user/feedback/feedback-list.vue");
const commission_withdrawal = () => import("@/views/user/commission/commission-withdrawal.vue");
//资讯管理
const news_list = () => import("@/views/news/news-list.vue");
const news_cate = () => import("@/views/news/news-cate.vue");
//广告位
const banner_list = () => import("@/views/banner/banner-list.vue");
const banner_cate = () => import("@/views/banner/banner-cate.vue");
//网站设置
const site_setting = () => import("@/views/shop-setting/site-setting.vue");
const payment = () => import("@/views/shop-setting/payment.vue");
const bank_account = () => import("@/views/shop-setting/bank-account.vue");
const eslink_print = () => import("@/views/shop-setting/eslink-print.vue");
//账号权限
const department_list = () => import("@/views/system/department-list.vue");
const job_list = () => import("@/views/system/job-list.vue");
const role_list = () => import("@/views/system/role-list.vue");
const menu_list = () => import("@/views/system/menu-list.vue");
const account_list = () => import("@/views/system/account-list.vue");
//日志管理
// const actionLog = () => import("@/views/system/actionLog.vue");
// const log_list = () => import("@/views/system/log-list.vue");
// 开发
const code = () => import("@/views/dev/code.vue");
const dev_api_web = () => import("@/views/dev/dev-api-web.vue");
const dev_api_admin = () => import("@/views/dev/dev-api-admin.vue");
const dev_setting = () => import("@/views/dev/dev-setting.vue");

const routes = [
	// {
	// 	path: "/test",
	// 	name: "test",
	// 	component: test,
	// 	meta: {
	// 		title: "网站路由",
	// 		deep: 1,
	// 	},
	// },
	{
		path: "/login",
		name: "login",
		component: login,
		meta: {},
	},
	// {
	// 	path: "/",
	// 	name: "index",
	// 	component: product_list,
	// 	meta: {
	// 		title: "网站概览",
	// 		deep: 1,
	// 	},
	// },
	{
		path: "/",
		name: "home-page",
		component: home_page,
		meta: {
			title: "首页",
			requireAuth:true
		},
	},
	

	{
		path: "/product-list",
		name: "product-list",
		component: product_list,
		meta: {
			root: "商品管理",
			title: "商品列表",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/product-form",
		name: "product-form",
		component: product_form,
		meta: {
			root: "商品管理",
			title: "发布商品",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/product-cate",
		name: "product-cate",
		component: product_cate,
		meta: {
			root: "商品管理",
			title: "商品分类",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/brand-cate",
		name: "brand-cate",
		component: brand_cate,
		meta: {
			root: "品牌管理",
			title: "品牌分类",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/points-product",
		name: "points-product",
		component: points_product,
		meta: {
			root: "商品管理",
			title: "积分商品",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/miaosha-list",
		name: "miaosha-list",
		component: miaosha_list,
		meta: {
			root: "商品管理",
			title: "秒杀商品",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/miaosha-detail",
		name: "miaosha-detail",
		component: miaosha_detail,
		meta: {
			root: "用户管理",
			title: "用户详情",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/miaosha-form",
		name: "miaosha-form",
		component: miaosha_form,
		meta: {
			root: "商品管理",
			title: "秒杀活动设置",
			deep: 2,
			requireAuth:true
		},
	},

	{
		path: "/package-product-list",
		name: "package-product-list",
		component: package_product_list,
		meta: {
			root: "商品管理",
			title: "组合商品",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/package-product-form",
		name: "package-product-form",
		component: package_product_form,
		meta: {
			root: "商品管理",
			title: "组合商品设置",
			deep: 2,
			requireAuth:true
		},
	},

	{
		path: "/gift-list",
		name: "gift-list",
		component: gift_list,
		meta: {
			root: "商品管理",
			title: "赠品设置",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/gift-form",
		name: "gift-form",
		component: gift_form,
		meta: {
			root: "商品管理",
			title: "赠品设置",
			deep: 2,
			requireAuth:true
		},
	},

	{
		path: "/product-unit",
		name: "product-unit",
		component: product_unit,
		meta: {
			root: "商品管理",
			title: "计量单位",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/product-setting",
		name: "product-setting",
		component: product_setting,
		meta: {
			root: "商品管理",
			title: "商品设置",
			deep: 2,
			requireAuth:true
		},
	},

	{
		path: "/warehouse-list",
		name: "warehouse-list",
		component: warehouse_list,
		meta: {
			root: "库存管理",
			title: "仓库列表",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/stock-list",
		name: "stock-list",
		component: stock_list,
		meta: {
			root: "库存管理",
			title: "商品库存",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/stock-record",
		name: "stock-record",
		component: stock_record,
		meta: {
			root: "库存管理",
			title: "库存明细",
			deep: 2,
			requireAuth:true
		},
	},

	{
		path: "/coupon-list",
		name: "coupon-list",
		component: coupon_list,
		meta: {
			root: "应用营销",
			title: "优惠券",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/coupon-form",
		name: "coupon-form",
		component: coupon_form,
		meta: {
			root: "应用营销",
			title: "优惠券信息",
			deep: 2,
			requireAuth:true
		},
	},

	{
		path: "/coupon-code-list",
		name: "coupon-code-list",
		component: coupon_code_list,
		meta: {
			root: "应用营销",
			title: "优惠码",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/coupon-code-form",
		name: "coupon-code-form",
		component: coupon_code_form,
		meta: {
			root: "应用营销",
			title: "优惠码信息",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/china-express",
		name: "china-express",
		component: china_express,
		meta: {
			root: "应用营销",
			title: "运费模版",
			deep: 2,
			requireAuth:true
		},
	},

	{
		path: "/foreign-express",
		name: "foreign-express",
		component: foreign_express,
		meta: {
			root: "应用营销",
			title: "外贸运费",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/foreign-trade-rule",
		name: "foreign-trade-rule",
		component: foreign_trade_rule,
		meta: {
			root: "应用营销",
			title: "外贸满减",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/points-sign-rule",
		name: "points-sign-rule",
		component: points_sign_rule,
		meta: {
			root: "应用营销",
			title: "积分签到规则",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/points-value-rule",
		name: "points-value-rule",
		component: points_value_rule,
		meta: {
			root: "应用营销",
			title: "积分价值规则",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/recharge-list",
		name: "recharge-list",
		component: recharge_list,
		meta: {
			root: "应用营销",
			title: "充值赠送",
			deep: 2,
			requireAuth:true
		},
	},
	// {
	// 	path: "/recharge-form",
	// 	name: "recharge-form",
	// 	component: recharge_form,
	// 	meta: {
	// 		root: "应用营销",
	// 		title: "充值赠送",
	// 		deep: 2,
	// 	},
	// },
	// {
	// 	path: "/reg-gift",
	// 	name: "reg-gift",
	// 	component: reg_gift,
	// 	meta: {
	// 		root: "应用营销",
	// 		title: "注册赠送",
	// 		deep: 2,
	// 	},
	// },



	{
		path: "/order-list",
		name: "order-list",
		component: order_list,
		meta: {
			root: "订单管理",
			title: "订单管理",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/order-detail",
		name: "order-detail",
		component: order_detail,
		meta: {
			root: "订单管理",
			title: "订单详情",
			deep: 2,
			requireAuth:true
		},
	},


	{
		path: "/points-order-list",
		name: "points-order-list",
		component: points_order_list,
		meta: {
			root: "订单管理",
			title: "积分订单",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/points-order-detail",
		name: "points-order-detail",
		component: points_order_detail,
		meta: {
			root: "订单管理",
			title: "积分订单详情",
			deep: 2,
			requireAuth:true
		},
	},


	{
		path: "/ship-list",
		name: "ship-list",
		component: ship_list,
		meta: {
			root: "订单管理",
			title: "发货管理",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/ship-detail",
		name: "ship-detail",
		component: ship_detail,
		meta: {
			root: "订单管理",
			title: "发货单详情",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/review-list",
		name: "review-list",
		component: review_list,
		meta: {
			root: "订单管理",
			title: "订单评价",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/invoice-list",
		name: "invoice-list",
		component: invoice_list,
		meta: {
			root: "订单管理",
			title: "订单发票",
			deep: 2,
			requireAuth:true
		},
	},

	{
		path: "/refund-list",
		name: "refund-list",
		component: refund_list,
		meta: {
			root: "订单管理",
			title: "售后管理",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/refund-detail",
		name: "refund-detail",
		component: refund_detail,
		meta: {
			root: "订单管理",
			title: "售后详情",
			deep: 2,
			requireAuth:true
		},
	},

	{
		path: "/store-list",
		name: "store-list",
		component: store_list,
		meta: {
			root: "门店管理",
			title: "门店列表",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/statistics-product",
		name: "statistics-product",
		component: statistics_product,
		meta: {
			root: "统计管理",
			title: "产品销量统计",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/product-transaction",
		name: "product-transaction",
		component: product_transaction,
		meta: {
			root: "统计管理",
			title: "商品统计",
			deep: 2,
			requireAuth:true
		},
	},

	{
		path: "/user-list",
		name: "user-list",
		component: user_list,
		meta: {
			root: "用户管理",
			title: "用户列表",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/user-detail",
		name: "user-detail",
		component: user_detail,
		meta: {
			root: "用户管理",
			title: "用户详情",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/user-level-rule",
		name: "user-level-rule",
		component: user_level_rule,
		meta: {
			root: "用户管理",
			title: "会员等级",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/agent-list",
		name: "agent-list",
		component: agent_list,
		meta: {
			root: "用户管理",
			title: "代理申請",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/feedback-list",
		name: "feedback-list",
		component: feedback_list,
		meta: {
			root: "用户管理",
			title: "意见反馈",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/commission-withdrawal",
		name: "commission-withdrawal",
		component: commission_withdrawal,
		meta: {
			root: "用户管理",
			title: "提现申请",
			deep: 2,
			requireAuth:true
		},
	},





	{
		path: "/news-list",
		name: "news-list",
		component: news_list,
		meta: {
			root: "资讯管理",
			title: "资讯内容",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/news-cate",
		name: "news-cate",
		component: news_cate,
		meta: {
			root: "资讯管理",
			title: "资讯分类",
			deep: 2,
			requireAuth:true
		},
	},

	{
		path: "/banner-list",
		name: "banner-list",
		component: banner_list,
		meta: {
			root: "广告位",
			title: "广告位",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/banner-cate",
		name: "banner-cate",
		component: banner_cate,
		meta: {
			root: "广告位",
			title: "广告位分类",
			deep: 2,
			requireAuth:true
		},
	},


	{
		path: "/site-setting",
		name: "site-setting",
		component: site_setting,
		meta: {
			root: "网站设置",
			title: "基础设置",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/payment",
		name: "payment",
		component: payment,
		meta: {
			root: "网站设置",
			title: "支付设置",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/bank-account",
		name: "bank-account",
		component: bank_account,
		meta: {
			root: "网站设置",
			title: "收款账户",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/eslink-print",
		name: "eslink-print",
		component: eslink_print,
		meta: {
			root: "网站设置",
			title: "打印设置",
			deep: 2,
			requireAuth:true
		},
	},




	{
		path: "/account-list",
		name: "account-list",
		component: account_list,
		meta: {
			root: "账号权限",
			title: "子账号管理",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/department-list",
		name: "department-list",
		component: department_list,
		meta: {
			root: "账号权限",
			title: "部门管理",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/job-list",
		name: "job-list",
		component: job_list,
		meta: {
			root: "账号权限",
			title: "岗位管理",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/menu-list",
		name: "menu-list",
		component: menu_list,
		meta: {
			root: "账号权限",
			title: "菜单管理",
			deep: 2,
			requireAuth:true
		},
	},
	{
		path: "/role-list",
		name: "role-list",
		component: role_list,
		meta: {
			root: "账号权限",
			title: "角色管理",
			deep: 2,
			requireAuth:true
		},
	},


	/* {
		path: "/code",
		name: "code",
		component: code,
		meta: {
			root: "开发",
			title: "表单生成",
		},
	},
	{
		path: "/dev-api-web",
		name: "dev-api-web",
		component: dev_api_web,
		meta: {
			root: "开发",
			title: "前端接口",
		},
	},
	{
		path: "/dev-api-admin",
		name: "dev-api-admin",
		component: dev_api_admin,
		meta: {
			root: "开发",
			title: "后端接口",
		},
	},
	{
		path: "/dev-setting",
		name: "dev-setting",
		component: dev_setting,
		meta: {
			root: "开发",
			title: "开发设置",
			deep: 2,
		},
	}, */

	{
		path: "*",
		redirect: "/",
	},
];

const scrollBehavior = (to, from, savedPosition) => {
	// console.log('滚动行为', to, from, savedPosition)
	return {
		x: 0,
		y: 0
	};
};

const router = new VueRouter({
	routes,
	// base: "/",
	base: "/admin",
	mode: "history",
	scrollBehavior,
});

router.beforeEach((to, from, next) => {
	let token = localStorage.getItem("token");
	let userId = localStorage.getItem("userId");
	let is_login_curr = token && userId;

	// debugger
	if (!is_login_curr && to.meta.requireAuth) {
		// debugger
		alertErr("请先登录");
		next("/login");
	} else {
		next();
	}
});

router.afterEach((to, from) => {
	// console.log("切换导航, 重新配置微信分享");
	// wxShare.getSign();
});

export default router;